﻿package com.tomvian.twodee.sideon.actions
{
	import flash.display.MovieClip;
	import com.tomvian.twodee.common.actions.Action;
	import com.tomvian.twodee.common.Actor;
	import com.tomvian.twodee.common.interactions.Interaction;
	import com.tomvian.maths.Vector2D;
	
	/**
	 * Swimming
	 * @author Thomas Vian
	 */
	public class Swimming extends Action
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public static const DISPLAY_SWIMMING:String = "swimming";
		
		public var water:Interaction;
		
		public var swimAccelX:Number;
		public var swimAccelY:Number;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function Swimming(actor:Actor, water:Interaction, swimAccelX:Number, swimAccelY:Number) 
		{
			super(actor);
			
			this.water = water;
			
			this.swimAccelX = swimAccelX;
			this.swimAccelY = swimAccelY;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function act():void
		{
			if (enabled)
			{
				if (water.interacting)
				{
					if (actorController.left) actorMass.velocity.x -= swimAccelX;
					if (actorController.right) actorMass.velocity.x += swimAccelX;
					
					if (actorController.up) actorMass.velocity.y -= swimAccelY;
					if (actorController.down) actorMass.velocity.y += swimAccelY;
				}
				else if (water.wasInteracting)
				{
					actor.returnToDefault();
				}
			}
		}
		
		override public function display():void 
		{
			actorState.state = DISPLAY_SWIMMING;
		}
	}
}